package com.cybertron.ironhide.search.controller;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cybertron.ironhide.search.util.SuggestUtil;

@Controller
@RequestMapping("/suggest")
public class SuggestController {

	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public String suggest(@RequestParam("q") String q) {
		List<String> suggests = SuggestUtil.suggest(q);
		if (suggests == null || suggests.size() == 0) {
			return "\n";
		}
		String[] suggestArr = new String[suggests.size()];
		suggests.toArray(suggestArr);
		return StringUtils.join(suggestArr, "\n");
	}
}
